﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RBOSS.Business.Presenters;
using RBOSS.Business.Views;
using RBOSS.WebUI.Models;

namespace RBOSS.WebUI
{
    public partial class BillingInformationForm : MasterSite, IBillingView
    {
        private BillingPresenter _billingPresenter;


        protected void Page_Load(object sender, EventArgs e)
        {
            lblErrorMessage.Visible = false;
            _billingPresenter = new BillingPresenter(this);
            if (!_billingPresenter.HasLogin())
            {
                Response.Redirect("Login.aspx?source=BillingInformationForm");
            }
            if (!Page.IsPostBack)
            {
                _billingPresenter.PopulateInfomation();
            }
            butNext.Click += NextClick;
            chkCopyBillingAddress.CheckedChanged += CopyBillingAddressClick;
        }

        private void CopyBillingAddressClick(object sender, EventArgs e)
        {
            _billingPresenter.CopyBilingAddress();
        }

        private void NextClick(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (_billingPresenter.IsCreditCardValid())
                {
                    _billingPresenter.SaveBillingInformation();
                    Response.Redirect("ShippingInformation.aspx");
                }
                else
                {
                    lblErrorMessage.Visible = true;
                    lblErrorMessage.Text = "Please use valid credit card to purchase. Please verify and try it again.";
                }
            }
        }

        public string CreditCardNumber
        {
            get { return txbCreditCartNumber.Text; }
            set { txbCreditCartNumber.Text = value; }
        }

        public string NameOnCard
        {
            get { return txbNameOnCard.Text; }
            set { txbNameOnCard.Text = value; }
        }

        public string ExpiredDate
        {
            get { return txbExpireDate.Text; }
            set { txbExpireDate.Text = value; }
        }

        public string SecurityNumber
        {
            get { return txbSecurityNumber.Text; }
            set { txbSecurityNumber.Text = value; }
        }

        public string Address1
        {
            get { return txbAddress1.Text; }
            set { txbAddress1.Text = value; }
        }

        public string Address2
        {
            get { return txbAddress2.Text; }
            set { txbAddress2.Text = value; }
        }

        public string City
        {
            get { return txbCity.Text; }
            set { txbCity.Text = value; }
        }

        public string State
        {
            get { return txbState.Text; }
            set { txbState.Text = value; }
        }

        public string Zip
        {
            get { return txbZip.Text; }
            set { txbZip.Text = value; }
        }

        public string Country
        {
            get { return txbCountry.Text; }
            set { txbCountry.Text = value; }
        }

        
    }
}